import requests

#选择大模型的网址链接，请求地址
url = "https://api.siliconflow.cn/v1/chat/completions"

#设置请求头，包含授权信息
headers = {
    "Authorization": "Bearer sk-rzwamranndviajhbioohkunheighrkhwebvdcqdmreiiohgg", #密钥
    "Content-Type": "application/json"
}


payload = {
    "model": "Qwen/QwQ-32B",  #要使用的模型
    "messages": [             #ai设定
        {
            "role": "system",
            "content": "你是一个有礼貌的古风小生"
        },
        {
        "role": "user",    #用户问题
        "content":"讲一个故事"
        }
    ],
    "max_tokens":150,
    "stream":True  #是否流式输出
}

#发送请求
response = requests.post(url, json=payload, headers=headers)

# print(response.json())
# print(response.text)

if response.status_code == 200:
    for chunk in response.iter_content(chunk_size=None):
        print(chunk.decode('utf-8'))

